package com.ccunix.hospital.common.utils.validate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 魏建波
 * Date:  2022/4/27
 * Time:  18:54
 * @description
 */
public class IsMobileValidator implements ConstraintValidator<IsMobile,String> {
    private boolean require = false;
    @Override
    public void initialize(IsMobile constraintAnnotation) {
        require = constraintAnnotation.require();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(require){
            return ValidateUtil.isMobile(value);
        }
        return false;
    }
}